<template>
  <div id="main">
    <h2>班级教学计划</h2>

    <div class="head">
      <el-button
        v-if="jurisdiction === '教学主管'"
        type="primary"
        style="margin:20px"
        @click="handleOpen('添加计划', 1)"
      >添加计划</el-button>
      <el-input
        v-model="searchTableInfo"
        placeholder="请输入搜索内容"
        style="width:240px;float: right;margin:20px;"
      />
    </div>
    <div id="table-area">
      <el-table
        v-loading="listLoading"
        :data="list.slice((currentPage - 1) * pagesize, currentPage * pagesize)"
        border
        fit
        highlight-current-row
      >
        <el-table-column
          label="序号"
          type="index"
          align="center"
        >
          <template scope="scope">
            <span>{{ (currentPage - 1) * pagesize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          prop="clazzTypeName"
          label="课程类型"
        />
        <el-table-column
          align="center"
          prop="technicalTypeName"
          label="技术类别"
        />
        <el-table-column
          align="center"
          prop="plansclazzPeopleTeacherName"
          label="授课教师"
        />
        <el-table-column
          align="center"
          prop="plansclazzStudentName"
          label="学生姓名"
        />

        <el-table-column
          align="center"
          prop="plansclazzTime"
          label="时间"
        />
        <el-table-column
          align="center"
          prop="plansclazzRoomName"
          label="地点"
        />
        <el-table-column
          align="center"
          prop="plansclazzTeachingSupervisorName"
          label="教学主管"
        />
        <el-table-column
          align="center"
          prop="plansclazzMedicalDirectorName"
          label="医疗主管"
        />
        <el-table-column
          align="center"
          prop="plansclazzPostTime"
          label="录入时间"
        />
        <el-table-column
          align="center"
          label="操作"
        >
          <template slot-scope="Scope">
            <el-button
              v-if="jurisdiction==='授课老师'||jurisdiction==='教学主管'"
              type="primary"
              icon="el-icon-edit"
              @click="handleOpen('修改计划', 2, Scope.row.plansclazzId)"
            >编辑</el-button>
            <el-button
              v-if="jurisdiction==='责任教师'||jurisdiction==='医疗主管'||jurisdiction==='教务主任'"
              type="primary"
              icon="el-icon-search"
              @click="handleOpen('修改计划', 2, Scope.row.plansclazzId)"
            >查看</el-button>
            <!-- <el-button type="danger" icon="el-icon-delete" @click="handleDelete(Scope.row.plansId) ">删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>

      <div id="pages">
        <el-pagination
          :current-page="currentPage"
          :page-sizes="[5, 10]"
          :page-size="pagesize"
          layout="total, sizes,prev, pager, next"
          :total="list.length"
          prev-text="上一页"
          next-text="下一页"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>

    <el-dialog
      v-if="jurisdiction == '授课老师'||( editType == 2 && jurisdiction === '教学主管') "
      title=""
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        ref="plans"
        :model="plans"
        label-position="top"
        :rules="rules"
      >
        <el-form-item
          prop="plansclazzStudentId"
          label="学生"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="plans.plansclazzStudentId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in child"
              :key="j.studentId"
              :value="j.studentId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>

        <el-form-item
          prop="plansclazzClazzId"
          label="班级"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="plans.plansclazzClazzId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in clazz"
              :key="j.classId"
              :value="j.classId"
              :label="j.className"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansclazzTeacherId"
          label="授课老师"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="plans.plansclazzTeacherId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffTeacher"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansclazzTeachingSupervisorId"
          label="教学主管"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="plans.plansclazzTeachingSupervisorId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffSupervisor "
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansclazzMedicalDirectorId"
          label="医疗主管"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="plans.plansclazzMedicalDirectorId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in staffMedicalDirector"
              :key="j.staffId"
              :value="j.staffId"
              :label="j.String"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansclazzTime"
          label="计划时间"
          :label-width="formLabelWidth"
        >
          <el-date-picker
            v-model="plans.plansclazzTime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
          />
        </el-form-item>

        <el-form-item
          prop="plansclazzRoomId"
          label="地点"
          :label-width="formLabelWidth"
        >
          <!-- <el-input v-model="teachTodo.teachingTodoRelatedPersonnel" autocomplete="off" maxlength="20" show-word-limit /> -->
          <el-select
            v-model="plans.plansclazzRoomId"
            placeholder="请选择"
            filterable
            style="width: 100%;"
          >
            <el-option
              v-for="j in room "
              :key="j.roomId"
              :value="j.roomId"
              :label="j.roomLoc"
            />
          </el-select>
        </el-form-item>
        <el-form-item
          prop="plansclazzStageGoal"
          label="阶段目标"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansclazzStageGoal"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />

        </el-form-item>
        <el-form-item
          prop="plansclazzTrainingPrograms"
          label="训练项目"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansclazzTrainingPrograms"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />

        </el-form-item>
        <el-form-item
          prop="plansclazzTeachingPreparation"
          label="教学准备"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansclazzTeachingPreparation"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
          />
          <el-form-item
            prop="plansclazzMattersNeedingAttention"
            label="注意事项"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="plans.plansclazzMattersNeedingAttention"
              autocomplete="off"
              maxlength="500"
              show-word-limit
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 20 }"
              placeholder="请输入内容"
            />

          </el-form-item>
        </el-form-item>
      </el-form>

      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          v-if="jurisdiction == '授课老师'||( editType == 2 && jurisdiction === '教学主管') "
          type="primary"
          @click="handleUpdate('plans')"
        >修 改</el-button>

        <el-button
          v-if="editType == 1 && jurisdiction == '教学主管'"
          type="primary"
          @click="handleAddUser('plans')"
        >添 加</el-button>
      </div>
    </el-dialog>
    <el-dialog
      v-else
      title=""
      :close-on-click-modal="false"
      :visible.sync="dialogFormVisible"
      :before-close="handleClose"
    >
      <el-form
        ref="plans"
        :model="plans"
        label-position="top"
        :rules="rules"
      >
        <el-form-item
          prop="plansclazzStudentId"
          label="学生"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans. plansclazzStudentName }}
          </el-tag>
        </el-form-item>

        <el-form-item
          prop="plansclazzClazzId"
          label="班级"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ ClassName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansclazzTeacherId"
          label="授课老师"
          :label-width="formLabelWidth"
        >

          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans.plansclazzPeopleTeacherName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansclazzTeachingSupervisorId"
          label="教学主管"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans. plansclazzTeachingSupervisorName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansclazzMedicalDirectorId"
          label="医疗主管"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ plans.plansclazzMedicalDirectorName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansclazzTime"
          label="计划时间"
          :label-width="formLabelWidth"
        >
          <el-date-picker
            v-model="plans.plansclazzTime"
            type="date"
            placeholder="选择日期"
            format="yyyy 年 MM 月 dd 日"
            value-format="yyyy-MM-dd"
            :readonly="readonly"
          />
        </el-form-item>

        <el-form-item
          prop="plansclazzRoomId"
          label="地点"
          :label-width="formLabelWidth"
        >
          <el-tag
            type="info"
            effect="plain"
          >
            {{ RoomName }}
          </el-tag>
        </el-form-item>
        <el-form-item
          prop="plansclazzStageGoal"
          label="阶段目标"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansclazzStageGoal"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />

        </el-form-item>
        <el-form-item
          prop="plansclazzTrainingPrograms"
          label="训练项目"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansclazzTrainingPrograms"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />

        </el-form-item>
        <el-form-item
          prop="plansclazzTeachingPreparation"
          label="教学准备"
          :label-width="formLabelWidth"
        >
          <el-input
            v-model="plans.plansclazzTeachingPreparation"
            autocomplete="off"
            maxlength="500"
            show-word-limit
            type="textarea"
            :autosize="{ minRows: 2, maxRows: 20 }"
            placeholder="请输入内容"
            :readonly="readonly"
          />
          <el-form-item
            prop="plansclazzMattersNeedingAttention"
            label="注意事项"
            :label-width="formLabelWidth"
          >
            <el-input
              v-model="plans.plansclazzMattersNeedingAttention"
              autocomplete="off"
              maxlength="500"
              show-word-limit
              type="textarea"
              :autosize="{ minRows: 2, maxRows: 20 }"
              placeholder="请输入内容"
              :readonly="readonly"
            />

          </el-form-item>
        </el-form-item>
      </el-form>

      <div
        slot="footer"
        class="dialog-footer"
      >
        <el-button
          v-if="jurisdiction == '授课老师'||( editType == 2 && jurisdiction === '教学主管') "
          type="primary"
          @click="handleUpdate('plans')"
        >修 改</el-button>

        <el-button
          v-if="editType == 1 && jurisdiction == '教学主管'"
          type="primary"
          @click="handleAddUser('plans')"
        >添 加</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { deleteplans } from '@/api/plans'
import { getAllclazzplans, getAllcp, getclazzplansById, updateclazzplans, getAllclazzplansByMedical, getAllclazzplansByDirector, getAllclazzplansByprincipal, getAllclazzplansAAA, addclazzplans, selectroom } from '@/api/plans'
import { selectstaff, getStaffStringD, getStaffStringmedical } from '@/api/staff'
import { selectStudent } from '@/api/child'
import { selectstaffTeacher, getStaffStringR } from '@/api/staff'

import { selectclazz } from '@/api/teachsummary'

import store from '@/store/index'
export default {
  data () {
    return {
      jurisdiction: '',
      BB: store.getters.userId,
      newplans: {

      },
      value: '',
      currentPage: 1, // 默认显示页面为1
      pagesize: 5, //    每页的数据条数
      // list: [],
      tableList: [],
      searchTableInfo: '',
      plans: {},
      room: {},
      readonly: false,
      listLoading: false,
      dialogFormVisible: false,
      editType: 1, // 1 添加 2 修改
      child: {},
      clazz: {},
      staff: {},
      ClassName: '',
      RoomName: '',
      staffSupervisor: {},
      staffMedicalDirector: {},
      staffTeacher: {},
      formLabelWidth: '200px',
      teacher: '',
      rules: {
        plansclazzStudentId: [
          { required: true, message: '学生不能为空', trigger: 'blur' }
        ],
        plansclazzMedicalDirectorId: [
          { required: true, message: '医疗主管不能为空', trigger: 'blur' }
        ],
        plansclazzClazzId: [
          { required: true, message: '班级不能为空', trigger: 'blur' }
        ],
        plansclazzTeachingSupervisorId: [
          { required: true, message: '教学主管不能为空', trigger: 'blur' }
        ],
        plansclazzTeacherId: [
          { required: true, message: '授课老师不能为空', trigger: 'blur' }
        ],
        plansclazzTime: [
          { required: true, message: '计划时间不能为空', trigger: 'blur' }
        ],
        plansclazzRoomId: [
          { required: true, message: '地点不能为空', trigger: 'blur' }
        ],
        plansclazzStageGoal: [
          { required: true, message: '阶段目标不能为空', trigger: 'blur' }
        ],
        plansclazzTrainingPrograms: [
          { required: true, message: '训练项目不能为空', trigger: 'blur' }
        ],
        plansclazzTeachingPreparation: [
          { required: true, message: '教学准备不能为空', trigger: 'blur' }

        ],
        plansclazzMattersNeedingAttention: [
          { required: true, message: '注意事项不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    // 根据计算属性模糊搜索
    list () {
      const searchTableInfo = this.searchTableInfo

      if (searchTableInfo) {
        // filter() 方法创建一个新的数组，新数组中的元素是通过检查指定数组中符合条件的所有元素。
        // 注意： filter() 不会对空数组进行检测。
        // 注意： filter() 不会改变原始数组。
        return this.tableList.filter(data => {
          // some() 方法用于检测数组中的元素是否满足指定条件;
          // some() 方法会依次执行数组的每个元素：
          // 如果有一个元素满足条件，则表达式返回true , 剩余的元素不会再执行检测;
          // 如果没有满足条件的元素，则返回false。
          // 注意： some() 不会对空数组进行检测。
          // 注意： some() 不会改变原始数组。
          return Object.keys(data).some(key => {
            // indexOf() 返回某个指定的字符在某个字符串中首次出现的位置，如果没有找到就返回-1；
            // 该方法对大小写敏感！所以之前需要toLowerCase()方法将所有查询到内容变为小写。
            return (
              String(data[key])
                .toLowerCase()
                .indexOf(searchTableInfo) > -1
            )
          })
        })
      }
      return this.tableList
    }
  },
  created () {
    this.jurisdiction = store.getters.roles[0]

    this.fetchData()
    this.getinfo()
  },
  methods: {
    formatSex: function (row, column, cellValue) {
      if (cellValue === '1') {
        return '女'
      } else if (cellValue === '0') {
        return '男'
      }
    },

    formatAge: function (row, column, cellValue) {
      if (cellValue === -1) {
        return '未填写'
      } else {
        return cellValue
      }
    },
    // 每页下拉显示数据
    handleSizeChange: function (size) {
      this.pagesize = size
    },
    // 点击第几页
    handleCurrentChange: function (currentPage) {
      this.currentPage = currentPage
    },
    getinfo: function () {
      selectStudent().then((resp) => {
        this.child = resp.data.records
      })
      selectstaff().then((resp) => {
        this.staff = resp.data.records
      })
      selectstaffTeacher().then((resp) => {
        this.staffTeacher = resp.data.records
      })

      getStaffStringR().then((resp) => {
        this.staffResponsibleTeacher = resp.data.records
      })

      getStaffStringmedical().then((resp) => {
        this.staffMedicalDirector = resp.data.records
      })
      getStaffStringD().then((resp) => {
        this.staffSupervisor = resp.data.records
      })
      selectclazz().then((resp) => {
        this.clazz = resp.data.records
      })
      selectroom().then((resp) => {
        this.room = resp.data.records
      })
    },
    handleClick (row) {

    },
    fetchData () {
      this.tableList = []
      this.listLoading = true
      if (this.jurisdiction === '医疗主管') {
        getAllclazzplansByMedical(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.clazzTypeName = data.data.records[i].clazzTypeName // 课程类型
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 录入时间
            this.newplans.plansclazzMedicalDirectorName = data.data.records[i].plansclazzMedicalDirectorName // 医疗主管姓名
            this.newplans.plansclazzPeopleTeacherName = data.data.records[i].plansclazzPeopleTeacherName// 授课教师
            this.newplans.plansclazzRoomName = data.data.records[i].plansclazzRoomName // 地点
            this.newplans.plansclazzStudentName = data.data.records[i].plansclazzStudentName // 学生姓名
            this.newplans.plansclazzTime = data.data.records[i].plansclazzTime // 时间
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 时间
            this.newplans.technicalTypeName = data.data.records[i].technicalTypeName // 技术类型
            this.newplans.plansclazzTeachingSupervisorName = data.data.records[i].plansclazzTeachingSupervisorName // 教学主管姓名
            this.newplans.plansclazzId = data.data.records[i].plansclazzId // 班级教学计划ID
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '责任教师') {
        getAllclazzplansByprincipal(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.clazzTypeName = data.data.records[i].clazzTypeName // 课程类型
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 录入时间
            this.newplans.plansclazzMedicalDirectorName = data.data.records[i].plansclazzMedicalDirectorName // 医疗主管姓名
            this.newplans.plansclazzPeopleTeacherName = data.data.records[i].plansclazzPeopleTeacherName// 授课教师
            this.newplans.plansclazzRoomName = data.data.records[i].plansclazzRoomName // 地点
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 时间
            this.newplans.plansclazzStudentName = data.data.records[i].plansclazzStudentName // 学生姓名
            this.newplans.plansclazzTime = data.data.records[i].plansclazzTime // 时间
            this.newplans.technicalTypeName = data.data.records[i].technicalTypeName // 技术类型
            this.newplans.plansclazzTeachingSupervisorName = data.data.records[i].plansclazzTeachingSupervisorName // 教学主管姓名
            this.newplans.plansclazzId = data.data.records[i].plansclazzId // 班级教学计划ID
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '教学主任') {
        getAllclazzplansAAA(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.clazzTypeName = data.data.records[i].clazzTypeName // 课程类型
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 录入时间
            this.newplans.plansclazzMedicalDirectorName = data.data.records[i].plansclazzMedicalDirectorName // 医疗主管姓名
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 时间
            this.newplans.plansclazzPeopleTeacherName = data.data.records[i].plansclazzPeopleTeacherName// 授课教师
            this.newplans.plansclazzRoomName = data.data.records[i].plansclazzRoomName // 地点
            this.newplans.plansclazzStudentName = data.data.records[i].plansclazzStudentName // 学生姓名
            this.newplans.plansclazzTime = data.data.records[i].plansclazzTime // 时间
            this.newplans.technicalTypeName = data.data.records[i].technicalTypeName // 技术类型
            this.newplans.plansclazzTeachingSupervisorName = data.data.records[i].plansclazzTeachingSupervisorName // 教学主管姓名
            this.newplans.plansclazzId = data.data.records[i].plansclazzId // 班级教学计划ID
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '教学主管') {
        getAllclazzplansByDirector(this.BB).then(data => {
          this.newplans

          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.clazzTypeName = data.data.records[i].clazzTypeName // 课程类型
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 录入时间
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 时间
            this.newplans.plansclazzMedicalDirectorName = data.data.records[i].plansclazzMedicalDirectorName // 医疗主管姓名
            this.newplans.plansclazzPeopleTeacherName = data.data.records[i].plansclazzPeopleTeacherName// 授课教师
            this.newplans.plansclazzRoomName = data.data.records[i].plansclazzRoomName // 地点
            this.newplans.plansclazzStudentName = data.data.records[i].plansclazzStudentName // 学生姓名
            this.newplans.plansclazzTime = data.data.records[i].plansclazzTime // 时间
            this.newplans.technicalTypeName = data.data.records[i].technicalTypeName // 技术类型
            this.newplans.plansclazzTeachingSupervisorName = data.data.records[i].plansclazzTeachingSupervisorName // 教学主管姓名
            this.newplans.plansclazzId = data.data.records[i].plansclazzId // 班级教学计划ID
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      } else if (this.jurisdiction === '教务主任') {
        getAllcp().then(data => {
          this.newplans
          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.clazzTypeName = data.data.records[i].clazzTypeName // 课程类型
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 录入时间
            this.newplans.plansclazzMedicalDirectorName = data.data.records[i].plansclazzMedicalDirectorName // 医疗主管姓名
            this.newplans.plansclazzPeopleTeacherName = data.data.records[i].plansclazzPeopleTeacherName// 授课教师
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 时间
            this.newplans.plansclazzRoomName = data.data.records[i].plansclazzRoomName // 地点
            this.newplans.plansclazzStudentName = data.data.records[i].plansclazzStudentName // 学生姓名
            this.newplans.plansclazzTime = data.data.records[i].plansclazzTime // 时间
            this.newplans.technicalTypeName = data.data.records[i].technicalTypeName // 技术类型
            this.newplans.plansclazzTeachingSupervisorName = data.data.records[i].plansclazzTeachingSupervisorName // 教学主管姓名
            this.newplans.plansclazzId = data.data.records[i].plansclazzId // 班级教学计划ID
            this.tableList.push(this.newplans)
            this.newplans = {}
          }

          this.listLoading = false
        })
      } else {
        getAllclazzplans(this.BB).then(data => {
          this.newplans
          for (var i = 0; i < data.data.records.length; i++) {
            this.newplans.clazzTypeName = data.data.records[i].clazzTypeName // 课程类型
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 录入时间
            this.newplans.plansclazzMedicalDirectorName = data.data.records[i].plansclazzMedicalDirectorName // 医疗主管姓名
            this.newplans.plansclazzPostTime = data.data.records[i].plansclazzPostTime // 时间
            this.newplans.plansclazzPeopleTeacherName = data.data.records[i].plansclazzPeopleTeacherName// 授课教师
            this.newplans.plansclazzRoomName = data.data.records[i].plansclazzRoomName // 地点
            this.newplans.plansclazzStudentName = data.data.records[i].plansclazzStudentName // 学生姓名
            this.newplans.plansclazzTime = data.data.records[i].plansclazzTime // 时间
            this.newplans.technicalTypeName = data.data.records[i].technicalTypeName // 技术类型
            this.newplans.plansclazzTeachingSupervisorName = data.data.records[i].plansclazzTeachingSupervisorName // 教学主管姓名
            this.newplans.plansclazzId = data.data.records[i].plansclazzId // 班级教学计划ID
            this.tableList.push(this.newplans)
            this.newplans = {}
          }
          this.listLoading = false
        })
      }
    },
    handleDelete (id) {
      this.$confirm('确认删除该记录？').then(() =>
        deleteplans(id).then(data => {
          this.$notify({
            title: '操作成功',
            type: 'success'
          })
          const totalPage = Math.ceil(
            (this.tableList.length - 1) / this.pagesize
          )
          const page =
            this.currentPage > totalPage ? totalPage : this.currentPage
          this.currentPage = this.currentPage < 1 ? 1 : page
          this.fetchData()
        })
      )
    },
    handleAddUser (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          addclazzplans(this.plans).then(resp => {
            this.$notify({
              title: '操作成功',
              type: 'success'
            })
            this.fetchData()
            this.plans = {}
          })
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    },

    handleOpen (title, type, id) {
      // this.plans = {}
      this.title = title
      this.editType = type
      if (type === 2) {
        getclazzplansById(id).then((resp) => {
          this.plans = resp.data.records

          if (this.jurisdiction === '授课教师' || this.jurisdiction === '教学主管') {
            this.readonly = false
          } else {
            for (let i = 0; i < this.clazz.length; i++) {
              if (this.plans.plansclazzClazzId == this.clazz[i].classId) {
                this.ClassName = this.clazz[i].className
              }
            }
            for (let i1 = 0; i1 < this.room.length; i1++) {
              if (this.plans.plansclazzRoomId == this.room[i1].roomId) {
                this.RoomName = this.room[i1].roomLoc
              }
            }
            this.readonly = true
          }
        })
        this.dialogFormVisible = true
      } else {
        this.dialogFormVisible = true
      }
    },
    handleClose () {
      this.dialogFormVisible = false
      // this.plans = {}
    },

    handleUpdate (formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          updateclazzplans(this.plans).then(resp => {
            this.$notify({
              title: '修改成功',
              type: 'success'
            })
            this.fetchData()
            this.plans = {}
          })
          this.dialogFormVisible = false
          return true
        } else {
          this.$notify({
            title: '请正确填写',
            type: 'error'
          })
          return false
        }
      })
    }
    // getAllJurisdiction() {
    //   getAllJurisdiction().then((resp) => {
    //     this.jurisdiction = resp.obj
    //   })
    // },
  }
}
</script>

<style scoped>
#main {
  margin-left: 5px;
  margin-right: 5px;
}
#table-area {
  margin-left: 10px;
  margin-right: 10px;
}
</style>
